package cn.webestar.scms.mybatisplus;

import cn.webestar.scms.mybatisplus.cache.CacheHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

/**
 * @author zgs
 */
@Slf4j
@Component
public class MybatisPlusRunner implements ApplicationRunner {

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Value("${app.cache.prefix}")
    private String prefix;

    @Value("${mybatis-plus.configuration.cache-expire:300}")
    private Integer expire;

    @Override
    public void run(ApplicationArguments args) {
        CacheHelper.setRedisTemplate(redisTemplate);
        CacheHelper.setPrefix(prefix + ":mapper");
        CacheHelper.setExpire(expire);
        log.info("[mybatis-plus-spring-boot-starter]:Init CacheHelper, expire={}", expire);
    }

}
